<?php

namespace Apps\AppApi\Method\Note;

use Apps\AppApi\Method\BaseMethod;
use PhalconPlus\Api\Common\ResultStatus;
use Apps\Common\Models\Inorout;
use Phalcon\Mvc\Model;


/**
 * 修改记事本收支分类
 * @author      545
 * @date        2016年3月4日
 * @version     1.1.2
 * @copyright   Copyright 2015 meelier.com
 */
class ModifyInorout extends BaseMethod
{
    /**
     * @var \Apps\Common\Models\AddInorout
     */
    private $success = 0;
    private $id = 0;

    public function run()
    {
        //验证是否登录
        if(false == $this->verifyUserAuth()){
            return false;
        }
        $id = $this->getDataItem('id',0);
    	$inorout_title = $this->getDataItem('title');
    	if (empty($inorout_title)&&empty($childtitle)){
    	    return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR,'标题为空');
    	}
    	
    	if ($id == 0){
    	    return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR,'id为空');
    	}
    	
    	//验证分类是否存在
    	$info = Inorout::findFirst("inorout_id = '{$id}' AND user_id = {$this->getUserAuth()->userId}");
    	
    	if (!$info){//验证分类是否存在
    	    return $this->errorLog(ResultStatus::QUERY_DATA_NOT_EXIST,"要修改的数据不存在");
    	}
    	
    	$data['inorout_title'] = $inorout_title;
    	
    	if ($info->update($data)){//保存分类
    	    $this->id = $info->inorout_id;
    	    $this->success = 1;
    	    
    	    $this->setResult([
    	        'success' => $this->success,
    	        'message' => '修改成功'
    	    ]);
    	    
    	}
    	else {
    	    $this->setResult(['success'=>0,'message'=>'修改失败！']);
    	}
        
        
    }

}